package com.yanggu.flink.datastream_api.partition

import org.apache.flink.streaming.api.scala._

//可以看到，数据被复制然后广播到了下游的所有并行任务中去了。
//broadcast:1> 1
//broadcast:2> 1
//broadcast:3> 1
//broadcast:4> 1
object BroadcastDemo {

  def main(args: Array[String]): Unit = {
    // 创建执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)
    // 读取数据源，并行度为 1
    val stream = env.fromElements(1)
    // 经广播后打印输出，并行度为 4
    stream
      .broadcast
      .print("broadcast").setParallelism(4)

    env.execute()
  }

}
